# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=pyalpm
pkgbase="python-${_realname}"
pkgname=("python-${_realname}")
pkgver=0.9.2
pkgrel=1
pkgdesc="Libalpm bindings for Python"
arch=('i686' 'x86_64')
license=('GPL')
url="https://gitlab.archlinux.org/archlinux/pyalpm"
depends=("python" "libarchive-devel")
makedepends=('gettext-devel'
             'heimdal-devel'
             'libarchive-devel'
             'libcurl-devel'
             'libgpgme-devel'
             'python-setuptools'
             'pacman')
provides=("python3-${_realname}")
conflicts=("python3-${_realname}")
replaces=("python3-${_realname}")
source=("git+https://gitlab.archlinux.org/archlinux/pyalpm.git#commit=4428779b28ad7df5efb7a3a3feb22a45e9510bfc"
        "0005-Use-pkg-config-add-LIBALPM_STATIC-env.-var.patch")
sha256sums=('SKIP'
            'f6954a6532bdc61f8149e5e98b13cadfdfcebff0d6c266408faec41428ab5eb9')

prepare() {
  cd "${srcdir}/${_realname}"

  patch -p1 -i "${srcdir}"/0005-Use-pkg-config-add-LIBALPM_STATIC-env.-var.patch

  # The git repo uses symlinks in the scripts folder to
  # the actual source files in the pycman folder. Patch
  # files created by git will therefore not contain any
  # changes to the files in scripts so copy the patched
  # ones across now.
  pushd "${srcdir}"/${_realname}
    for _file in deptest query remove sync upgrade version; do
      cp -f pycman/action_${_file}.py scripts/pycman-${_file}
    done
  popd
}

build() {
  cd "${srcdir}/${_realname}"

  LIBALPM_STATIC=1 \
    /usr/bin/python setup.py build
}

package() {
  cd "${srcdir}/${_realname}"

  /usr/bin/python setup.py install --prefix=/usr --root="${pkgdir}" -O1
}
